(: Ex4 :)
(:
    opening xml database mondial-europe
   getting country node having car_code attribute equals to D 
   getting border node
   getting country attribute of the border node
:)
let $countries := doc('/db/mondial/mondial-europe.xml')/mondial/country[@car_code='D']/border/@country
(: 
   getting all population node of countries having a car_code in country list retrieved before
:)
let $pop := doc('/db/mondial/mondial-europe.xml')/mondial/country[@car_code=$countries]/population
(:
   create a node containing information about countries having a border with germany
   with attibute country_count equals to the number of node in $countries
   pop_sum attribute equals to the sum of all population node selected before
   pop_avg attribute equals to the average of all population node selected before
:)
return <Info_on_countries_which_border_Germany
country_count="{count($countries)}"
pop_sum="{sum($pop)}"
pop_avg="{avg($pop)}"
/>
